<template>
  <div class="app-container aero">
    <el-form :inline="true" :model="searchForm" size="mini">
      <el-form-item label="大屏名称">
        <el-input v-model="searchForm.title" placeholder="请输入大屏名称" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSearch">查询</el-button>
      </el-form-item>
    </el-form>
    <el-row class="list-container" :gutter="24">
      <el-col :span="6">
        <div class="designItem" @click="showForm(false, null)">
          <div class="create-btn">
            <i class="el-icon-plus"></i>
          </div>
        </div>
      </el-col>
      <el-col :span="6" v-for="item in tableData" :key="item.id">
        <div
          class="designItem"
          :style="{
            backgroundImage: item.designImgId
              ? 'url(' + imgUrl + item.designImgId + ')'
              : 'none',
          }"
        >
          <div class="editMask">
            <div
              class="designItem-title"
            >
              {{ item.title }}
            </div>
            <div style="text-align: center; line-height: 45px;margin-bottom:10px;">
              <el-button
                class="m-button"
                plain
                type="primary"
                icon="el-icon-edit-outline"
                @click="toDesign(item)"
                >设计</el-button>
                <el-button
                class="m-button"
                type="danger"
                icon="el-icon-delete"
                @click="deleteItem(item)"
                >删除</el-button>
            </div>
            <div style="text-align: center; line-height: 45px">
              <el-button
                class="m-button"
                type="success"
                icon="el-icon-view"
                @click="toView(item)"
                >访问</el-button>
                <el-button
                class="m-button"
                type="primary"
                icon="el-icon-share"
                @click="toShare(item)"
                >分享</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-pagination
      background
      class="pagination"
      style="margin-top: 20px;"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageConfig.pageNo"
      :page-size="pageConfig.pageSize"
      :page-sizes="[10, 30, 50, 100]"
      :total="pageConfig.total"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <DesignerForm ref="designerForm" @refreshTable="loadData" />
  </div>
</template>

<script>
import { pageListApi, deleteApi } from "@/api/DesignerApi";
import { fileUrl } from "/env";
import DesignerForm from "@/views/manage/form/DesignerForm";

export default {
  name: "DesignList",
  components: { DesignerForm },
  data() {
    return {
      imgUrl: fileUrl + "/file/img/",
      searchForm: { groupName: "" },
      pageConfig: {
        pageNo: 1,
        pageSize: 10,
        total: 0,
      },
      tableData: [],
    };
  },
  created() {
    this.onSearch();
  },
  methods: {
    toView(item) {
      window.open("/#/view?id=" + item.id);
    },
    toDesign(item) {
      window.open("/#/design?id=" + item.id);
    },
    deleteItem(item) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteApi(item.id).then(() => {
            this.$message.success("删除成功");
            this.loadData();
          });
        })
        .catch(() => {});
    },
    toShare(item) {
      let text = window.location.host + "/#/view?id=" + item.id;
      this.$alert(text, "分享链接").catch(() => {});
    },
    onSearch() {
      this.pageConfig.pageNo = 1;
      this.pageConfig.pageSize = 10;
      this.loadData();
    },
    loadData() {
      pageListApi(Object.assign(this.searchForm, this.pageConfig)).then(
        (res) => {
          this.tableData = res.data.records;
          this.pageConfig.total = res.data.total;
        }
      );
    },
    handleSizeChange(val) {
      this.pageConfig.pageSize = val;
      this.loadData();
    },
    handleCurrentChange(val) {
      this.pageConfig.pageNo = val;
      this.loadData();
    },
    showForm(isEdit, row) {
      let rowData = {};
      if (isEdit) {
        rowData = JSON.parse(JSON.stringify(row));
      }
      this.$refs.designerForm.opened(isEdit, rowData);
    },
  },
};
</script>

<style scoped>
.editMask {
  width: 100%;
  height: 100%;
  position: absolute;
  display: none;
  background-color: rgba(0, 0, 0, 0.6);
}
.designItem {
  height: 240px;
  position: relative;
  background-color: #2b3340;
  color: #eee;
  line-height: 30px;
  background-size: cover;
  border-radius: 5px;
}
.designItem:hover .editMask {
  border-radius: 5px;
  display: block;
}
.designItem-title{
  text-indent: 1em; 
  text-align: center; 
  font-size: 24px;
  font-weight: bold;
  font-family: '黑体';
  color: #fff;
  margin-top: 10%;
  margin-bottom: 5%;
}
.app-container {
  padding: 45px;
  border-radius: 10px;
  user-select: none;
}
.list-container {
  min-height: 500px;
}
.pagination{
  text-align: center;
}
.m-button{
  width: 100px;
  height: 45px;
}
.create-btn{
  text-align: center;
  font-size: 64px;
  line-height: 240px;
}
.create-btn:hover{
  color: #000;
  border-radius: 5px;
  background-image: radial-gradient(circle at 20% 20%, #99CCCC, #7171B7);
  background-size: 400%;
  border: 1px solid #000;
  transition: linear 0.2s; 
}
@keyframes bganimation {
      0% {
        background-position: 0% 50%;
      }

      50% {
        background-position: 100% 50%;
      }

      100% {
        background-position: 0% 50%;
      }
}
</style>
